package com.example.teatea.dao;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class CheckMember {
    public boolean checkMember(String phone){
        Connection conn = null;
        ResultSet res = null;
        try {
            Properties info = new Properties();
            info.load(new FileInputStream("src\\main\\resources\\com\\example\\teatea\\sql.properties"));
            String user = info.getProperty("user");
            String password = info.getProperty("password");
            String Driver = info.getProperty("Driver");
            String url = info.getProperty("url");
            //注册驱动
            Class.forName(Driver);
            //获取连接
            conn= DriverManager.getConnection(url,user,password);
            String sql = "select * from members where mPhone = ?";
            PreparedStatement presta = conn.prepareStatement(sql);
            presta.setString(1,phone);
            res = presta.executeQuery();
            if(res.next()){
                return true;
            }
        }catch(SQLException e){
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return false;
    }
}
